package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-22 15:53
 **/
public class LeetCode448 {

    public List<Integer> findDisappearedNumbers(int[] nums) {
        int n = nums.length;
        //为num-1索引处的值+n,那么当遍历数组nums的值时,如果nums的值小于等于n说明,该位置索引i+1值缺失,添加到集合中,返回
        for (int num : nums) {
            int x = (num - 1) % n;
            nums[x] += n;
        }

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (nums[i] <= n) {
                list.add(i + 1);
            }
        }
        return list;
    }

}
